package oad.a233.v1.axcore;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class OADTitleListView extends ViewGroup {

	private Context _Context;
	private AttributeSet _Attrs;
	
	private int _ViewHeight =30;
	public void set_ViewHeight(int _ViewHeight) {
		this._ViewHeight = _ViewHeight;
	}
	
	private RelativeLayout _TitleView;
	
	private int _lvItemLayout = R.layout.titlelv_lvitem_opal;	
	public int get_lvItemLayout() {
		return _lvItemLayout;
	}
	public void set_lvItemLayout(int _lvItemLayout) {
		this._lvItemLayout = _lvItemLayout;
	}

	public int get_TitleLayout() {
		return _TitleLayout;
	}
	
	private int _TitleLayout = R.layout.titlelv_bar_title_opal;	
	public void set_TitleLayout(int _TitleLayout) {
		this._TitleLayout = _TitleLayout;
	}
	private OADListView _ListView;
	public OADListView get_ListView() {
		return _ListView;
	}

	public OADTitleListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		_Context = context;
		_Attrs = attrs;
		
		InitView();
	}

	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		l=this.getPaddingLeft();
		r= _TitleView.getMeasuredWidth()+this.getPaddingRight();
		t = this.getPaddingTop();
		b = _ViewHeight + this.getPaddingBottom();
		
	   _TitleView.layout(l, t, r, b);		
		
		b+=_ListView.getMeasuredHeight();
		t+=_ViewHeight;
		_ListView.layout(l, t, r, b);
	}
	
	private void InitView()
	{			
	
		try
		{		
			
			_TitleView = (RelativeLayout) OADTitleListView.inflate(_Context,_TitleLayout,null);
			
			this.addView(_TitleView);
			
			 _ListView = new OADListView(_Context,_Attrs);
			 _ListView.setCacheColorHint(Color.parseColor("#00000000"));
			 
			 this.addView(_ListView);
			 this.setBackgroundResource(R.drawable.oad_list_cornor_round);
			
			 
			
		}
		catch(Exception e)
		{
			Log.e("InitView", e.getMessage());
		}
	    
	    
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
	//	_TitleView.draw(canvas);
	//	_ListView.draw(canvas);
		
		super.onDraw(canvas);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
	
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		try
		{		
			_ListView.measure(widthMeasureSpec, heightMeasureSpec);
			
			
			 
			
			heightMeasureSpec = MeasureSpec.makeMeasureSpec(_ViewHeight, MeasureSpec.EXACTLY);
			//widthMeasureSpec = MeasureSpec.makeMeasureSpec(widthMeasureSpec, MeasureSpec.EXACTLY);
			
			_TitleView.measure(widthMeasureSpec, heightMeasureSpec);
		//	_TitleView.setLayoutParams(new LayoutParams(_TitleView.getMeasuredWidth(),_ViewHeight));
			
		}
		catch(Exception e)
		{
			Log.e("onMeasure", e.getMessage());
		}
		
		
	}
	
	public void ChangeTitleLayOut(int layOutId)
	{
		_TitleView = (RelativeLayout) OADTitleListView.inflate(_Context,layOutId,null);	
		
	}
	
	public void SetTitle(String title)
	{
		TextView tv = (TextView) _TitleView.findViewById(R.id.oad_title_name);
		
		tv.setText(title);
	}

}
